<template>
  <div>
    <div class="bottom">
      <el-carousel :interval="4000" type="string" height="10vh" style="margin-top:6vh">
        <el-carousel-item v-for="(list, index) in dataList" :key="index">
          <ul>
            <li v-for="(item, idx) in list" @click="pageJump(item.value)" :key="idx"
              style="margin-left:6px;cursor: pointer;">
              <img :src="getImageSrc(item.value)">
              <p>{{ item.name }}</p>
            </li>
          </ul>
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>

<script>

import { checkUser, checkUserCqbc, getDicts_archive, getPath, getPathCqbc } from "@/api/homePage";

export default {
  name: "quickEntryButton",
  props: ['source'],
  data() {
    return {
      dataList: [],
      style: '', // 中铁集中式样式
      addressOption: [],

    }
  },
  methods: {
    init(val) {
      if (this.source == '1') {
        this.style = 'margin-top: 1.5vh'
      } else {
        this.style = 'margin-top: 3vh;'
      }

      this.dataList = val;
      this.getDataSource()
      getDicts_archive('JUMP_ADDRESS').then(response => {
        this.addressOption = response.data
      })
      // console.log(this.dataList, val)
    },



    getDataSource() {
      let newDataList = []
      let current = 0
      if (this.dataList && this.dataList.length > 0) {
        for (let i = 0; i <= this.dataList.length - 1; i++) {
          if (i % 6 !== 0 || i === 0) {
            if (!newDataList[current]) {
              newDataList.push([this.dataList[i]])
            } else {
              newDataList[current].push(this.dataList[i])
            }
          } else {
            current++
            newDataList.push([this.dataList[i]])
          }
        }
      }
      this.dataList = [...newDataList]

      console.log(this.dataList, "000000000000000")
    },
    getImageSrc(item) {
      // 根据元素的值获取对应的图片路径
      switch (item) {
        case 'DAZL':
          return require("@/assets/images/a-54-danganzhengli.png");
        case 'JYGL':
          return require('@/assets/images/a-54-jieyueguanli.png');
        case 'MLJS':
          return require("@/assets/images/a-54-mulujiansuo.png");
        case 'LYTJ':
          return require('@/assets/images/a-54-liyongtongji.png');
        case 'DAJS':
          return require('@/assets/images/a-54-danganjieshou.png');
        case 'QWJS':
          return require('@/assets/images/a-54-quanwenjiansuo.png');
        case 'GXPT':
          return require('@/assets/images/a-54-gongxiangpingtai.png');
        case 'CQBC':
          return require('@/assets/images/a-54-changqibaocun.png');
        case 'JSC':
          return require('@/assets/images/a-54-jsc.png')
        default:
          return '';
      }
    },
    pageJump(item) {
      console.log(item, "--------------------")
      // 根据元素的值跳转不同页面
      switch (item) {
        case 'DAZL':
          return this.$router.push({ path: this.addressOption.find(item => item.dictValue == 'DAZL') != undefined ? this.addressOption.find(item => item.dictValue == 'DAZL').dictLabel : '/filesManage/filesManageMenu' });
        case 'JYGL':
          return this.$router.push({ path: this.addressOption.find(item => item.dictValue == 'JYGL') != undefined ? this.addressOption.find(item => item.dictValue == 'JYGL').dictLabel : '/archiveBorrow/archiveBorrow' });
        case 'MLJS':
          return this.$router.push({ path: this.addressOption.find(item => item.dictValue == 'MLJS') != undefined ? this.addressOption.find(item => item.dictValue == 'MLJS').dictLabel : "/archiveBorrow/catalogueSearch" });
        case 'LYTJ':
          return this.$router.push({ path: this.addressOption.find(item => item.dictValue == 'LYTJ') != undefined ? this.addressOption.find(item => item.dictValue == 'LYTJ').dictLabel : '/statistics/utilizingStatistics' });
        case 'DAJS':
          return this.$router.push({ path: this.addressOption.find(item => item.dictValue == 'DAJS') != undefined ? this.addressOption.find(item => item.dictValue == 'DAJS').dictLabel : "/digitalizeReceive/archiveReception" });
        case 'QWJS':
          return this.$router.push({ path: this.addressOption.find(item => item.dictValue == 'QWJS') != undefined ? this.addressOption.find(item => item.dictValue == 'QWJS').dictLabel : "/archiveBorrow/fullTextSearch" });
        case 'JSC':
          const routeData = this.$router.resolve({ path: "/cockpit" }); //打开新窗口
          return window.open(routeData.href, '_blank');
        case 'GXPT':
          this.jumpGxpt();
          break; 
        case 'CQBC':
          this.jumpCqbc();
          break; 
        default:
          return '';
      }
    },
    // 跳转共享平台
    jumpGxpt() {
      checkUser().then(response => {
        if (response.data.msg == '200') {
          getPath().then(response => {
            // window.open(response.data.path + '?token=' + encodeURIComponent(response.data.token))
            window.location.href = response.data.path + '?token=' + encodeURIComponent(response.data.token)
          })
        }
        else {
          this.$message({ message: response.data.msg, type: 'warning' })
        }
      })
    },
    jumpCqbc() {
      checkUserCqbc().then(response => {
        if (response.data.msg == '200') {
          getPathCqbc().then(response => {
            // window.open(response.data.path + '?token=' + encodeURIComponent(response.data.token))
            window.location.href = response.data.path + '?token=' + encodeURIComponent(response.data.token)
          })
        } else {
          this.$message({ message: response.data.msg, type: 'warning' })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
ul,
li {
  overflow: hidden;
  margin: 0;
  // padding: 0;
}

.bottom {
  ul {
    //margin-top: 3vh;
  }

  ul li {
    float: left;
    list-style: none;
    width: 11vh;
    margin-right: 1%;
    margin-top: 1%;
    // padding: 2% 3%;
    font-size: 1.8vh;
    background-size: 100% 100%;
    text-align: center;

    p {
      margin: 0;
    }
  }
}
</style>
